﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/App.Master" Inherits="System.Web.Mvc.ViewPage<IList<Ornament.MemberShip.User>>" %>

<%@ Import Namespace="Ornament.MemberShip.Permissions" %>
<%@ Import Namespace="Ornament.Web" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    用户管理
</asp:Content>
<asp:Content ID="content4" ContentPlaceHolderID="PageTitle" runat="server">
    用户管理
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    
    <script language="javascript" type="text/javascript">
        var hadLoadCreateWizard = false;

        $(document).ready(function () {


            $("#unlockButton").button({ icons: { primary: "ui-icon-plusthick"} });
            $("#approvedButton").button({ icons: { primary: "ui-icon-check"} });
            $("#Create").button({ icons: { primary: "ui-icon-plus"} }).click(function () {
                location = '<%=Url.Action("CreateWizard")%>';
            }); ;


            $("#approvedButton,#unlockButton").click(function () {
                var ids = [];
                $("[name=selectUser]:checked").each(function () {
                    ids.push($(this).val());
                });
                if (ids.length == 0)
                    return;

                var isLockFun = $(this).attr('id') == "unlockButton",
                msg = isLockFun ? "解锁以下账号" : "激活以下帐户使用",
                actionUrl = isLockFun ? '<%=this.Url.Action("UnlockUser") %>' : '<%=this.Url.Action("Approve") %>';

                if (confirm(msg + ids)) {
                    $.post(actionUrl, { loginId: ids.join(",") },
                  function (data) {
                      oAlert(data.Message);
                      if (data.Success) {
                          $(ids).each(function () {
                              $(isLockFun ? "#lock_" : "#app_" + this + " div").addClass("ui-icon-check").removeClass("ui-icon-closethick");
                          });
                      }
                  });
                }
            });
        });     
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div style="margin: 5px">
        <%if (OrnamentContext.Current.HasRight("User", UserOperator.Modify))
          {%>
        <button title="创建新用户" id="Create">
            创建</button>
        <%
          }%>
        <%if (OrnamentContext.Current.HasRight("User", UserOperator.Lock))
          {%>
        <button id="unlockButton">
            解锁</button>
        <%
          }%>
        <%if (OrnamentContext.Current.HasRight("User", UserOperator.Approve))
          {%>
        <button id="approvedButton">
            同意使用</button>
        <%
          }%>
    </div>
    <table>
        <thead>
            <tr>
                <th>
                </th>
                <th style="width: 100px">
                    登录名
                </th>
                <th style="width: 100px">
                    名称
                </th>
                <th>
                    email
                </th>
                <th>
                    是否锁定
                </th>
                <th>
                    是否可使用
                </th>
                <th>
                    最后操作时间
                </th>
            </tr>
        </thead>
        <tbody>
            <%foreach (var user in this.Model)
              {%>
            <tr>
                <td>
                    <input type="checkbox" name="selectUser" value="<%=user.LoginId %>" />
                    <%=Html.ActionLink("编辑","Edit", new {id=user.LoginId})%>
                    <%=Html.ActionLink("分配","Assign",new {id=user.LoginId,title="分配角色和用户分组"}) %>
                </td>
                <td>
                    <%=user.LoginId %>
                </td>
                <td>
                    <%=user.Name %>
                </td>
                <td>
                    <%=user.Information.Email %>
                </td>
                <td id="lock_<%=user.LoginId%>" align="center">
                    <div class="ui-icon <%=user.IsLockout?"ui-icon-check":"ui-icon-closethick"%>">
                    </div>
                </td>
                <td id="app_<%=user.LoginId%>" align="center">
                    <div class="ui-icon <%=user.IsApproved?"ui-icon-check":"ui-icon-closethick"%>">
                    </div>
                </td>
                <td>
                    <%=user.LastActivityDate %>
                </td>
            </tr>
            <%
              }%>
        </tbody>
    </table>
</asp:Content>
